package core.controller
{
	import com.greensock.TweenLite;
	
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.utils.clearTimeout;
	import flash.utils.setTimeout;

	/**
	 * @author lonely
	 * @date Feb 6, 2013
	 */
	public class RemoveCardController
	{
		private var list:Array;
		
		private var callback:Function;
		
		public function RemoveCardController(list:Array,callback:Function = null)
		{
			this.list = list;
			this.callback = callback;
			this.execute();
		}
		
		private var clearID:uint;
		
		/**
		 * 暂时默认掉用,如果有需要再公开 
		 * 
		 */		
		protected function execute():void {
			var cardEffect:CardEffect = list[0]; ;
			for(var i:int = 1; i < list.length; i++){
				var object:CardEffect = list[i];
				TweenLite.to(object,0.1,{x:cardEffect.x});
			}
			clearID = setTimeout(showNextEffect,400);// 执行回收牌的效果
		}
		
		protected function showNextEffect():void {
			for(var i:int = 0; i < list.length; i++){
				var object:CardEffect = list[i];
				object.hideCardEffect();
			}
			clearTimeout(clearID);
			clearID = setTimeout(complete,800);
		}
		
		private function complete():void {
			clearTimeout(clearID);
			if(this.callback != null){
				this.callback();
				this.callback = null;
			}
		}
	}
}